// components/job-selector/job-selector.js
const { category, values } = require('../../utils/const/job')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    value: {
      type: String,
      value: '',
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    range: [category, values[0]],
    values: [0, 0],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * @desc 当下拉选择切换时
     */
    onPickerChange(e) {
      let {detail: { value: [categoryIndex, jobIndex] }} = e
      let [category, values] = this.data.range
      let value = `${category[categoryIndex]} - ${values[jobIndex]}`

      this.triggerEvent('change', { value, values: [categoryIndex, jobIndex] })
    },

    /**
     * @desc 两列选择切换
     */
    onMultiPickerColumnChange(e) {
      let { detail: { column, value: index } } = e

      if (column === 0) {
        this.setData({
          range: [
            category,
            values[index],
          ]
        })
      }
    },
  }
})
